using Godot;
using System;

public partial class WizardEnemy : CharacterBody2D
{

	Node2D visuals;
	VelocityComponent velocityComponent;

	bool isMoving = false;

	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{

		visuals = GetNode<Node2D>("Visuals");
		velocityComponent = GetNode<VelocityComponent>("VelocityComponent");

		GetNode<HurtboxComponent>("HurtboxComponent").Hit += OnHit;

	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
		//移动组件
		if(isMoving){
			velocityComponent.AccelerateToPlayer();
		}else{
			velocityComponent.Decelerate();
		}
		velocityComponent.Move(this);

		var moveSign = Math.Sign(Velocity.X);
		if(moveSign != 0){
			visuals.Scale = new Vector2(moveSign,1);
		}
	}

	public void SetIsMoving(bool moving){
		this.isMoving = moving;
	}

	public void OnHit(){
		GetNode<RandomStreamPlayer2dComponent>("HitRandomAudioPlayerComponent").PlayRandom();
	}
}
